<!--
	作者：956911785@qq.com
	时间：2018-10-18
	描述：文化课辅导班-添加
-->

<template>
	<Modal :title="title" v-model="modal0" width="800px">
		<Form ref="params" :model="params" :rules="ruleValidate" :label-width="100" label-position="left">
			<div style="width:100%;height:500px; overflow-y: scroll;">
  
		        <div style="width:100%;height: 60px;line-height: 60px;float:left;">
		        	<div style="width: 50%;text-align: left;float: left;" align="left">
				        <FormItem  prop="nj" label="年级">
				        	<Input v-model="params.nj" @on-change="setfbdmc()" style="width: 70%" clearable ></Input>
		        		</FormItem>
		        	</div>
		        	<div style="width: 50%;text-align: left;float: left;" align="left">
				        <FormItem  prop="bj" label="班级">
				        	<Input v-model="params.bj" style="width: 70%" clearable @on-change="setfbdmc()"></Input>
		        		</FormItem>
		        	</div>
		        </div>
		     
		      	<div style="width:100%;height: 60px;line-height: 60px;float:left;">
		        	<div style="width: 50%;text-align: left;float: left;" align="left">
				        <FormItem  prop="km" label="科目">
				        	<Input v-model="params.km" placeholder="请输入科目" clearable style="width: 70%" @on-change="setfbdmc()"></Input>
		        		</FormItem>
		        	</div>
		        	<div style="width: 50%;text-align: left;float: left;" align="left">
				        <FormItem  prop="mc" label="辅导班名称">
				        	<Input v-model="params.mc" placeholder="请输入辅导班名称" clearable style="width: 70%"></Input>
		        		</FormItem>
		        	</div>
		        </div>

				<div style="width:100%;height: auto;float:left;">
		        	<FormItem  prop="jj" label="辅导班简介">
			        	<Input v-model.trim="params.jj" type="textarea" :rows="10" style="width: 86.5%;" placeholder="请输入教师简介！" />
        			</FormItem>
		        </div>

				<div style="width:100%;height: 60px;line-height: 60px;float:left;">
		        	<div style="width: 50%;text-align: left;float: left;" align="left">
				        <FormItem  prop="fy" label="费用">
				        	<Input v-model="params.fy" placeholder="请输入费用" clearable style="width: 70%"></Input>
		        		</FormItem>
		        	</div>
		        	<div style="width: 50%;text-align: left;float: left;" align="left">
				        <FormItem  prop="xe" label="人员限额">
				        	<Input v-model="params.xe" placeholder="请输入人员限额" clearable style="width: 70%"></Input>
		        		</FormItem>
		        	</div>
		        </div>
		        
		        <div style="width:100%;height: 60px;line-height: 60px;float:left;">
		        	<div style="width: 50%;text-align: left;float: left;" align="left">
				        <FormItem  prop="sksj" label="授课时间">
				        	<DatePicker v-model="skTime" @on-change="sjchange" transfer type="datetime" format="yyyy-MM-dd HH:mm" placeholder="请选择授课时间" style="width:70%"></DatePicker>
		        		</FormItem>
		        	</div>
		        	<div style="width: 50%;text-align: left;float: left;" align="left">
				        <FormItem  prop="skdd" label="授课地点">
				        	<Input v-model="params.skdd" placeholder="请输入授课地点" clearable style="width: 70%"></Input>
		        		</FormItem>
		        	</div>
		        </div>    
		        
		        
		        <div style="width:100%;height: 60px;line-height: 60px;float:left;">
		        	<div style="width: 100%;text-align: left;float: left;" align="left">
				        <FormItem  prop="bmzlsm" label="报名资料说明">
				        	<Input v-model="params.bmzlsm" placeholder="请输入报名资料说明" clearable style="width: 70%"></Input>
		        		</FormItem>
		        	</div>
		        </div>    
		        
		        
		        <div style="width:50%;height: 60px;line-height: 60px;float:left;text-align: center;">
		        	<Button type="info" v-on:click="openwhksfmodal">
		        		<Icon type="md-add" />其它项目费用
		        	</Button>
		        	<whksf ref="whksf" v-on:onsure="sureWhkxm"  v-bind:whkxm="params.whksf"></whksf>
		        </div>
		      
		       <div style="width:50%;height: 60px;line-height: 60px;float:left;text-align: center;">
		        	<Button type="info" v-on:click="openTeachermodal">
		        		<Icon type="md-add" />添加辅导老师
		        	</Button>
		        	<addteacher ref="addteacher" v-on:onsure="sureTeaxm"  v-bind:teachers="params.teachers"></addteacher>
		        </div>
				
		   </div> 
	    </Form>
	   	<div slot="footer">
	    	<Button type="text"  @click="closeModal()">取消</Button>
	    	<Button type="primary" @click="addsave()" >确定</Button>
	    </div>
     </Modal>
</template>

<script>
	import whksf from "./whksf";
	import addteacher from "./addteacher";
	
	export default {
		name:"tconent",
		props: {
    		teas:{
    			type:Object,	
    			default: function() {
					return null
				}
    		},
    		title:{
    			type:String,	
    		},
    	},
		data() {
			//长度控制
			const lenPass = (rule, str, callback) => {
			  if(str.length>rule.length){
			  	 callback(new Error('字符串长度在1-'+rule.length+'之间！'));
			  }
			  return callback();
			};
			
			//正整数控制（1-20）
			const zzsPass = (rule, value, callback) => {
				let reg = /^\+?[1-9][0-9]*$/; 
				if(!reg.test(value)){
				    callback(new Error('请输入正整数！'));
				}else if(value>20){
					callback(new Error('数值不能大于20！'));
				}
				return callback();
				
			};
			//正整数控制
			const zzsPass1 = (rule, value, callback) => {
			    let reg = /^\+?[1-9][0-9]*$/; 
				if(!reg.test(value)){
				    callback(new Error('请输入正整数！'));
				}else{
				  	return callback();
				}
			};
			//正数控制
			const zsPass = (rule, value, callback) => {
			    let reg = /^\+?[1-9]|[1-9][0-9]*$/; 
				if(!reg.test(value)){
				    callback(new Error('请输入正数！'));
				}else{
				  	return callback();
				}
			};
			return {
				skTime:new Date(),
				ruleValidate: {
		            nj: [
		                {required: true, message: '请输入年级！', trigger: 'blur'},
		                {validator:zzsPass,trigger:'blur'}
		            ],
		            bj: [
		            	{required: true, message: '请输入班级！', trigger: 'blur'},
		                {validator:zzsPass,trigger:'blur'}
		            ],
		         	km: [
		                {required: true, message: '请输入科目名称！', trigger: 'blur'},
		                {length:20,validator:lenPass,trigger:'blur'}
		            ],
		            mc: [
		                {required: true, message: '请输入辅导班名称！', trigger: 'blur'},
		                {length:50,validator:lenPass,trigger:'blur'}
		            ],
					jj: [
		                {required: true, message: '请输入简介！', trigger: 'blur'},
		                {length:1000,validator:lenPass,trigger:'blur'}
		            ],
					fy: [
		                {required: true, message: '请输入该辅导班的收费！', trigger: 'blur'},
		                {validator:zsPass,trigger:'blur'}
		            ],
					xe: [
		                {required: true, message: '请输入人员限额！', trigger: 'blur'},
		                {validator:zzsPass1,trigger:'blur'}
		            ],
		      },   
                modal0:false,
                params:{
                	wid:"",
					csid:"",
					nj:"",
					bj:"",
					km:"",
					mc:"",
					jj:"",
					fy:"",
					jlxzsj:"",
					jlscsj:"",
					wstate:"",
					xe:"",
					sksj:"",
					skdd:"",
					bmzlsm:'',
					whksf:[],
					teachers:[]
                },
			}
		},
		components: {
			whksf,
			addteacher
		},
		methods: {
			addsave:function(){
				this.$refs.params.validate((valid) => {
					if (valid){
						const params={...this.params};
						this.$emit("addsave",params);
                    }
               })
	        }, 
			
            closeModal(){
	      	    this.modal0 = false;
	      	    this.resetpar();
	        },
	        resetpar(){
	        	this.params={
	        		wid:"",
					csid:"",
					nj:"",
					bj:"",
					km:"",
					mc:"",
					jj:"",
					fy:"",
					jlxzsj:"",
					jlscsj:"",
					wstate:"",
					xe:"",
					sksj:"",
					skdd:"",
					bmzlsm:'',
					whksf:[],
					teachers:[]
				};
	        },
	        openwhksfmodal(){
	        	this.$refs.whksf.modal1 = true;
	        },
	        
	        sureWhkxm: function(values) {
				this.params.whksf = [...values];
			},
			
			
			openTeachermodal(){
				this.$refs.addteacher.modal1 = true;
			},
			sureTeaxm: function(values) {
				this.params.teachers = [...values];
			},
			
			setfbdmc(){
				const nj=this.params.nj;
				const bj=this.params.bj;
				const km=this.params.km;
				var fdbmc="";
				if(nj!=""){
					fdbmc+=this.converNumber(parseInt(nj))+"年级";
				}
				if(bj!=""){
					fdbmc+="（"+bj+"）"+"班";
				}
				if(km!=""){
					fdbmc+=km;
				}
				fdbmc+="辅导班";
				this.params.mc=fdbmc;
			},
			converNumber(num){
				const numarr=['一','二','三','四','五','六','七','八','九',"十",
				'十一','十二','十三','十四','十五','十六','十七','十八','十九',"二十"];
				var n=num-1;
				return numarr[n];
			},
			
			sjchange(e){
				this.params.sksj=e;
			}
			
		},
		mounted() {
		
  			
		},
		watch:{
			modal0(news,olds){
				if(!news){
					 this.resetpar();
				}else{
					this.params={...this.teas};
					if(this.params.sksj){
						this.skTime=new Date(this.params.sksj);
					}
					
				}
			}
		},
		computed: {
			
		}
		
	}
</script>

<style scoped="scoped">
	
</style>



